﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SoftwareApproach.TestingExtensions;

namespace TestProject.Assessment
{
    public static class AssertExtension
    {
        public static string ShouldStartWith(this string source, string substring)
        {
            StringAssert.StartsWith(source, substring);
            return source;
        }

        public static string ShouldContain(this string source, string substring)
        {
            StringAssert.Contains(source, substring);
            return source;
        }
    }

    [TestClass]
    public class AssertExtensionTest
    {
        [TestMethod]
        public void ShouldStartWith_CheckIfAAAAAAStartsWithAAA_ShouldPass()
        {
            //arrange
            const string str = "AAABBB";

            //action
            //assert
            str.ShouldStartWith("AAA");
        }

        [TestMethod]
        [ExpectedException(typeof(AssertFailedException))]
        public void ShouldStartWith_CheckIfAAAAAAStartsWithBBB_ShouldNotPass()
        {
            //arrange
            const string str = "AAABBB";

            //action
            //assert
            str.ShouldStartWith("BBB");
        }

        [TestMethod]
        public void ShouldStartWith_SomeString_ShouldReturnThisString()
        {
            //arrange
            const string str = "AAABBB";

            //action
            var result = str.ShouldStartWith("AAA");

            //assert
            result.ShouldBeSameAs(str);
        }

        [TestMethod]
        public void ShouldContain_CheckIfAAABBBContainsAB_ShouldPass()
        {
            //arrange
            const string str = "AAABBB";

            //action
            //assert
            str.ShouldContain("AB");
        }

        [TestMethod]
        [ExpectedException(typeof(AssertFailedException))]
        public void ShouldContain_CheckIfAAABBBContainsCC_ShouldNotPass()
        {
            //arrange
            const string str = "AAABBB";

            //action
            //assert
            str.ShouldContain("CC");
        }

        [TestMethod]
        public void ShouldContain_SomeString_ShouldReturnThisString()
        {
            //arrange
            const string str = "AAABBB";

            //action
            var result = str.ShouldContain("AAA");

            //assert
            result.ShouldBeSameAs(str);
        }
    }
}
